﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SW_SoftBully.Controllers;
using SW_SoftBully.Models.ModuloAdministracion.Edificio;
using System.Data.SqlClient;
using log4net;
using SW_SoftBully.Models.ModuloAdministracion.TipoAreaComun;

namespace SW_SoftBully.Models.ModuloAdministracion.TipoAreaComun
{
    public class TipoAreaComunDAO
    {
        public List<TipoAreaComunBean> Listartipoareacomun(TipoAreaComunBean tipoareacomun)
        {
            try{
                List<TipoAreaComunBean> listatipoAreaComun = new List<TipoAreaComunBean>();

                String cadenaConfiguracion = ConfigurationManager.ConnectionStrings["SoftBully"].ConnectionString;

                SqlConnection sqlCon = new SqlConnection(cadenaConfiguracion);

                sqlCon.Open();

                string commandString = "SELECT * FROM tipo_area_comun WHERE estado = 1";

                SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);

                SqlDataReader dataReader = sqlCmd.ExecuteReader();

                while (dataReader.Read()){
                    TipoAreaComunBean Tipoareacomun = new TipoAreaComunBean();
                    Tipoareacomun.nombre_area = Convert.ToString(dataReader["Nombre_Area"]);
                    Tipoareacomun.Estado = Convert.ToInt32(dataReader["Estado"]);
                    listatipoAreaComun.Add(Tipoareacomun);
                }
                dataReader.Close();
                sqlCon.Close();

                return listatipoAreaComun;
            }
            catch (Exception e)
            {
                String men = e.ToString();
                tipoareacomun.conexion = men;
                return null;
            }
        }                     
    }
}
